// #ifdef H5
import COS from 'cos-js-sdk-v5';
// #endif

// #ifdef MP-WEIXIN
import COS from 'cos-wx-sdk-v5';
// #endif

// @ts-ignore
let cos = new COS({
  SecretId: 'AKIDnfdUGrKesuiKi166HG5jKtItQq9Q5gEa', // 身份识别 ID
  SecretKey: 'GI7jBVq9LQYhzIXgbhiYHviMrAFEqLap', // 身份密钥
  SimpleUploadMethod: 'putObject'
});
export function uploadImage(files: Array<any>): Promise<Array<string>> {
  return new Promise((resolve, reject) => {
    let count = 0;
    let result: Array<string> = [];
    for (var index in files) {
      var filePath = files[index].path;
      var Key = filePath.substr(filePath.lastIndexOf('/') + 1);
      cos.putObject(
        {
          Bucket: 'wish-1300401836', //对象储存桶的名称
          Region: 'ap-beijing', //所属地域
          Key: 'images/' + Key,
          Body: files[index],
          onProgress: function (info) {
            console.log('进度条', JSON.stringify(info));
          }
        },
        function (err, data) {
          if (err) {
            console.log('上传失败', err);
          } else {
            //console.log('上传成功', data);
          }
          count++;
          console.log(result,"resiult=============")
          if (count >= files.length) {
            resolve(result.concat(data.Location));
          }
        }
      );
    }
  });
}
